<template>
	<view>
		<scroll-view scroll-y="true" class="scrollbox" :scroll-top='scrolltop'>
			<view class="formbd u-radius-10 u-p-20">
				<view class="flex-between u-p-tb-20">
					<text>序号</text>
					<text>{{index}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>发布背景</text>
					<text>{{nickname||'暂无背景'}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>邮箱</text>
					<text>{{email}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>课程名称</text>
					<text>{{c_name}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>教学领域</text>
					<text>{{teachingArea}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>被引用次数</text>
					<text>{{refcount}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>教学目标</text>
					<text>{{teachingAim}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>重点难点</text>
					<text>{{importantDifficult}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>使用学生年龄</text>
					<text>{{age}}</text>
				</view>
				<u-line></u-line>
				<view class="flex-between u-p-tb-20">
					<text>教学设备及场地</text>
					<text>{{teachingEtc}}</text>
				</view>
				<u-line></u-line>
				<view class="u-p-tb-20">
					<view>教学主要环节</view>
					<textarea class="u-m-t-20" maxlength="-1" :disabled='start==2' v-model="teachingSteps"></textarea>
				</view>
			</view>
			<view class="sureuse flex-center " @click="showscroll">
				<text class="sureuseitem u-radius-10" :class="is_use?'active':''">
					确认使用
				</text>
			</view>
			<template>
				<view v-if="show">
					<view class="u-p-20">
						<text>评分标准及建议评分用语</text>
						<textarea v-model="proposal"  style="width: 100%;" :disabled='start==2' maxlength="-1" class="u-m-t-20 minetextarea" placeholder="从发布课程直接导入"></textarea>
					</view>
					<view class="u-p-20">
						<text>教学建议</text>
						<textarea v-model="teacherSuggess" :disabled='start==2' style="width: 100%;" maxlength="-1" class="u-m-t-20 minetextarea" placeholder="AI自动生成"></textarea>
					</view>
					<view class="u-p-20">
						<text>对本教案的反馈意见</text>
						<textarea v-model="teacherFeedback"  maxlength="-1" :disabled='start==2' style="width: 100%;" class="u-m-t-20 minetextarea"
							placeholder="请输入对本教案的反馈意见,最多200字"></textarea>
					</view>
					<view class="sureuse flex-center u-p-tb-150 " @click="submit">
						<text class="sureuseitem u-radius-10">
							提交
						</text>
					</view>
				</view>
			</template>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				is_use:false,
				show: false,
				id: '',
				index: '',
				classarea: '',
				importantDifficult: '',
				c_name: '',
				newAim: '',
				proposal: '',
				scoringCriteria: '',
				teachingAim: '',
				teachingArea: '',
				teachingEtc: '',
				teachingSteps: '',
				nickname: '',
				email: '',
				teacherSuggess: '',
				teacherFeedback: '',
				refcount: '',
				age: '',
				scrolltop: 0,
				start:0
			};
		},
		onLoad(opt) {
			this.id = opt.id
			this.index = Number(opt.index) + 1
			this.init()
		},
		methods: {
			submit() {
				if(this.start!=0||this.start!=2){
					this.$api.post('/assistant/xCourse/quoteCourse', {
						id: this.id,
						info: this.teacherFeedback
					}).then(res => {
						if (res.code == 200) {
							this.$toast(res.message)
							setTimeout(() => {
								uni.navigateBack()
							}, 1000)
						}
					})
				}
				
			},
			showscroll(event) {
				if(this.is_use) return
				this.is_use = true
				this.show = true
				uni.showLoading({
					title:'AI生成中~'
				})
				this.start = 2
				this.star()
				this.$api.get('/aiModel/generateLessonPlan',{
					templateCode:'t-003',
					param:'课程名称:' + this.c_name + ',' + '教学领域:' + this.teachingArea + ','
					+ '教学目标:' + this.teachingAim + ','+ '重点难点:' + this.importantDifficult + ','
					+ '适用学生年龄:' + this.age + ','+ '教学主要环节:' + this.teachingSteps + ','
					+ '教学设备及场地:' + this.teachingEtc 
					
				}).then(res=>{
					this.teacherSuggess = res.data
					uni.hideLoading()
					this.start =3
				}).catch(err=>{
					uni.hideLoading()
					this.start =1
					this.is_use = true
					uni.$toast('生成失败！请重试')
				})
			},
			star() {
				var that = this
				for(var i=0;i<10;i++){
				  (function(j){
				     setTimeout(function(){
					   that.scrolltop+=65
					   console.log( that.scrolltop)
				     },j*10)
				   })(i)
				}
			},
			init() {
				this.$api.get('/assistant/xCourse/getInfo', {
					id: this.id,
				}).then(res => {
					this.refcount = res.data.refcount
					this.teachingArea = res.data.teachingArea
					this.importantDifficult = res.data.importantDifficult
					this.c_name = res.data.c_name
					this.teachingAim = res.data.teachingAim
					this.nickname = res.data.background
					
					this.value = res.data.is_show == 1 ? true : false
					this.newAim = res.data.newAim
					this.email = res.data.email
					this.teacherSuggess = res.data.teacherSuggess
					this.teachingEtc = res.data.teachingEtc
					this.teacherFeedback = res.data.teacherFeedback
					this.teachingSteps = res.data.teachingSteps
					this.proposal = res.data.proposal
					this.age = res.data.age
				})
			},
		}
	}
</script>

<style lang="scss">
	.formbd {
		border: 1rpx solid rgba(216, 216, 216, 1);
		box-sizing: border-box;
		width: 686rpx;
		margin: 30rpx auto;
	}
	.minetextarea{
		padding: 20rpx;
		box-sizing: border-box;
		border: 1rpx solid #999;
		border-radius: 20rpx;
	}
	.sureuse {
		color: #fff;
		margin: 50rpx 0 30rpx 0;

		.sureuseitem {
			background-color: $main-color;
			padding: 20rpx 150rpx;
		}
		.active{
			background-color: #999;
			color: #fff;
		}
	}

	.scrollbox {
		height: 95vh;
	}
</style>